package com.pay.weixin.util;

import java.io.Serializable;

/**
 * 操作执行结果。
 * Created by ThreeManTeam on 2015/12/18.
 */
public class TmtResult<T> implements Serializable {
	public enum TmtResultCode {
		RC_FAIlURE,
		RC_SUCCESS,
		RC_REDIRECT //跳转
	}

	private String reqUuid;
	private String resUuid;
	private TmtResultCode resCode;
	private String resMessage;
	private T resData;
	private Long resLong;

	public TmtResult() {
	}

	public TmtResult(String reqUuid, String resUuid, TmtResultCode resCode, String resMessage, T resData) {
		this.reqUuid = reqUuid;
		this.resUuid = resUuid;
		this.resCode = resCode;
		this.resMessage = resMessage;
		this.resData = resData;
	}

	public String getReqUuid() {
		return reqUuid;
	}

	public void setReqUuid(String reqUuid) {
		this.reqUuid = reqUuid;
	}

	public String getResUuid() {
		return resUuid;
	}

	public void setResUuid(String resUuid) {
		this.resUuid = resUuid;
	}

	public TmtResultCode getResCode() {
		return resCode;
	}

	public void setResCode(TmtResultCode resCode) {
		this.resCode = resCode;
	}

	public String getResMessage() {
		return resMessage;
	}

	public void setResMessage(String resMessage) {
		this.resMessage = resMessage;
	}

	public T getResData() {
		return resData;
	}

	public void setResData(T resData) {
		this.resData = resData;
	}

	public boolean isSuccess() {
		return this.resCode == TmtResultCode.RC_SUCCESS;
	}

	public Long getResLong() {
		return resLong;
	}

	public void setResLong(Long resLong) {
		this.resLong = resLong;
	}

	public static <T> TmtResult success() {
		return success("执行成功");
	}

	public static <T> TmtResult success(String resMessage) {
		if (resMessage == null)
			resMessage = "执行成功";

		return success(resMessage, null);
	}

	public static <T> TmtResult success(T resData) {
		return success("执行成功", resData);
	}

	public static <T> TmtResult success(String resMessage, T resData) {
		if (resMessage == null)
			resMessage = "执行成功";

		return new TmtResult("0", "0",
				TmtResultCode.RC_SUCCESS,
				resMessage,
				resData);
	}

	public static <T> TmtResult failure(String resMessage, T resData) {
		if (resMessage == null)
			resMessage = "执行失败";

		return new TmtResult("0", "0",
				TmtResultCode.RC_FAIlURE,
				resMessage,
				resData);
	}

	public static <T> TmtResult failure(String resMessage) {
		if (resMessage == null)
			resMessage = "执行失败";

		return failure(resMessage, null);
	}

}
